<?php
namespace Home\Controller;
use Think\Controller;
class DeviceController extends CommonController {
	public function index(){
		$id = I('id');
        $cate_id = M('device')->where(array('id'=>$id))->getField('cate_id');
        if ($cate_id == 1) {
            $this->redirect('Light/index',array('id'=>$id),2,'页面跳转中');
        }
        if ($cate_id == 2) {
            $this->redirect('Mouse/index',array('id'=>$id),2,'页面跳转中');
        }
     	$data = M('device a')
    		->where(array('a.id'=>$id))
    		->field('a.name,b.status,b.cate_name,b.pest,a.code_num,a.cate_id')
    		->join("left join zm_device_cate b on a.cate_id=b.id")
    		->find();
    	$status = M('device_status')
    		->where('cate_id='.$data['cate_id'])
    		->field('status_name,id,is_next')
    		->select();
    	/*$data['status'] = M('device_status')
    		->where('cate_id='.$data['cate_id'])
    		->field('status_name,id,is_next')
    		->select();*/
    	$pest_id = explode(',', $data['pest']);
    	/*dump($pest_id);exit;
    	$map['id'] = array('in',explode(',', $data['pest']));*/
    	/*$data['pest_name'] = M('animal')
    		->where($map)
    		->field('name,id')
    		->select();*/
    	$pest_name = M('animal')
    		->where(array('id'=>array('in',$pest_id)))
    		->field('name,id')
    		->select();
    
    	$this->assign('data',$data);
    	$this->assign('status',$status);
    	$this->assign('pest_name',$pest_name);
    	$this->display();
    }
    public function status(){
    	$id = I('id');
    	$two_status = M('device_status_next')
    				->where(array('st_id'=>$id,'fu_id'=>0))
    				->field('id,name,is_next')
    				->select();
    	
    	$this->assign('two_status',$two_status);
    	$this->display();
    }
    public function status_next(){
    	$id = I('id');
    	$three_status = M('device_status_next')
    					->where(array('fu_id'=>$id))
    					->field('id,name,is_next')
    					->select();
    	$this->assign('t_status',$three_status);
    	$this->display();
    }

}